﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using QLLopHoc.XuLyDuLieu;
using QLLopHoc.DoiTuongDuLieu;

namespace QLLopHoc
{
    public partial class frmCapNhatGV : DevExpress.XtraEditors.XtraForm
    {
        public frmCapNhatGV(DTLopHoc lh)
        {
            InitializeComponent();
            lb_TenLH.Text = lh.TenLopHoc;
            List<DTGiangVien> dsgv = XLGiangVien.LayDSGiangVien();
            cmbGiangVien.Items.AddRange(dsgv.ToArray());
            cmbGiangVien.DisplayMember = "HoTen";
            for (int i = 0; i < dsgv.Count; ++i)
            {
                if (dsgv[i].MSSV == lh.MaGiangVien)
                {
                    cmbGiangVien.SelectedIndex = i;
                    break;
                }
            }
        }

        private void frmCapNhatGV_Load(object sender, EventArgs e)
        {

        }
         public DTLopHoc LopHoc 
        { 
            get 
            { 
                DTLopHoc lh = new DTLopHoc(); 
                lh.TenLopHoc = lb_TenLH.Text; 
                int idx = cmbGiangVien.SelectedIndex; 
                if (idx > -1) 
                    lh.MaGiangVien = ((DTGiangVien)cmbGiangVien.Items[idx]).MSSV;
                return lh;
            }
        } 

        private void btnBo_Click(object sender, EventArgs e)
        {
            this.DialogResult = DialogResult.Cancel; 
        }

        private void btnCậpnhật_Click(object sender, EventArgs e)
        {
            if (cmbGiangVien.SelectedIndex == -1)
            {
                MessageBox.Show("Chưa có đủ thông tin.");
                return;
            }
            this.DialogResult = DialogResult.OK; 
        }
    }
}